package models;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Formula;

@SuppressWarnings("serial")
@Entity
@Table(name="sys_orgn")
public class Orgn extends IdEntity{
	
	
	
	
	@Formula("(select COUNT(*) from sys_orgn d where d.parent_id = 0 or d.parent_id is NULL)")
    private int isRoot;
	
	@Formula("(select COUNT(*) from sys_orgn d where d.parent_id = id)")
    private int subOrgnCount;
	
	private String name;
	private Integer position;
	private String code;
	

	private String type;
	@ManyToOne(fetch = FetchType.EAGER)
	private Zone zone;
	
	@ManyToOne(fetch = FetchType.EAGER)
	private Orgn parent;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Orgn getParent() {
		return parent;
	}

	public void setParent(Orgn parent) {
		this.parent = parent;
	}

	public Integer getPosition() {
		return position;
	}

	public void setPosition(Integer position) {
		this.position = position;
	}

	public int getIsRoot() {
		return isRoot;
	}

	public void setIsRoot(int isRoot) {
		this.isRoot = isRoot;
	}

	public int getSubOrgnCount() {
		return subOrgnCount;
	}

	public void setSubOrgnCount(int subOrgnCount) {
		this.subOrgnCount = subOrgnCount;
	}

	public Zone getZone() {
		return zone;
	}

	public void setZone(Zone zone) {
		this.zone = zone;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
}
